package perl.compiler;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Semaphore;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import perl.compiler.utils.CodeLoader;
import perl.lexical.classes.Token;
import perl.lexical.classes.TokenClassEnum;

public class Compiler {

	public static void main(String[] argc) {

		try {

			//Read source code
			
			List<StringBuilder> fileCode = CodeLoader.readFile("code.txt");
			
			// Create MAP for tokens from analizer
			
			Map<Integer, Token> tokens = new TreeMap<Integer, Token>();
			
			// LEXICAL ANALIZATION
			
			LexicalAnalyzer lexicalAnalizer = new LexicalAnalyzer();

				
			tokens = lexicalAnalizer.analize(fileCode);
				
			for (Integer token : tokens.keySet()) {
				System.out.println(tokens.get(token));
			}
			
			// SYNTAX ANALIZATION
			
			SyntaxAnalizer syntaxAnalizer = new SyntaxAnalizer(tokens);
			
			String input = "(100+200)/50a";
			
			syntaxAnalizer.analize();
			
			
			//SEMANTIC ANALIZATION
			
			SemantycAnalizer semantycAnalizer = new SemantycAnalizer(tokens);
			
			semantycAnalizer.analize();
			 
			/*String testString = "$#fdsf";
			Pattern pnumber = Pattern.compile("([1-9]\\d*|0)(\\.\\d+)?[^\\.]*");		
			Pattern oper = Pattern.compile("[\\$\\@]?[_,a-z, A-Z].*");
			Matcher m = oper.matcher(testString);
			System.out.println(m.matches());*/
			
		} catch (IOException e) {
			e.printStackTrace();
			
		}catch  (Exception e) {
			e.printStackTrace();
		}

	}
}
